package com.pitaya.avatar.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateTemplate;

import com.pitaya.avatar.dao.IHouseDAO;
import com.pitaya.avatar.domain.House;
import com.pitaya.avatar.util.HouseMatcher;

public class HouseDAO extends HibernateTemplate implements IHouseDAO{

	public boolean delete(House house) {
		Session session = getSession();
		
		
		
		session.delete(house);
		return true;
	}

	public boolean insert(House house) {
		Session session = getSession();
		
		
		
		session.save(house);
		return true;
	}

	public List<House> query(House house) {
		List<House> list = new ArrayList<House>();
		Session session = getSession();
		list = session.createCriteria(House.class).add(Restrictions.like("name", house.getName())).list();
		
		
		return list;
	}

	public boolean update(House house) {
		Session session = getSession();
		House houseOld = (House)session.get(House.class, house.getHid());
		if(HouseMatcher.update(houseOld, house)) {
			session.update(houseOld);
			return true;
		}
		return false;
	}

}
